Skip to content

Conversation

@mre
Copy link
Member

@mre mre commented Oct 1, 2025

Issue

When running the API on a clean database instance, migrations were failing with the following errors:

Error 1: Duplicate column 'publishOn'

Error: Duplicate column name 'publishOn'
    at PromisePool.query (/Users/mendler/Code/openpodcast/api/node_modules/mysql2/promise.js:341:22)
    at DBInitializer.runMigration (/Users/mendler/Code/openpodcast/api/src/db/DBInitializer.ts:113:24)
  code: 'ER_DUP_FIELDNAME',
  errno: 1060,
  sql: 'ALTER TABLE anchorPodcastEpisodes ADD COLUMN publishOn DATETIME DEFAULT NULL AFTER created',
  sqlMessage: "Duplicate column name 'publishOn'"

Error 2: Table modification fails for hosterPodcastMetrics

Error: Table 'openpodcast.hosterPodcastMetrics' doesn't exist
  code: 'ER_NO_SUCH_TABLE',
  errno: 1146,
  sql: 'ALTER TABLE hosterPodcastMetrics MODIFY dimension ENUM(...)',
  sqlMessage: "Table 'openpodcast.hosterPodcastMetrics' doesn't exist"

Root Cause

schema.sql contained changes that were supposed to be applied via migrations:

  • The publishOn column (added by migration 6)
  • The listeners and subscribers enum values for hosterPodcastMetrics (added by migration 17)

When migrations ran after schema.sql on a fresh DB, they tried to add/modify things that already existed.

Solution

Remove migration changes from schema.sql so it reflects the base state before any migrations run. Migrations then apply changes incrementally:

  • ✅ Removed publishOn column from anchorPodcastEpisodes table (will be added by migration 6)
  • ✅ Removed 'listeners' and 'subscribers' from hosterPodcastMetrics dimension enum (will be added by migration 17)

This ensures schema.sql and migrations don't conflict on fresh installs while maintaining compatibility with existing databases that have already run these migrations.

Testing

Tested with:

docker exec api-db-1 mysql -u openpodcast -popenpodcast -e "DROP DATABASE IF EXISTS openpodcast; CREATE DATABASE openpodcast;"
make dev

All migrations now run successfully on a fresh database.

When running the API on a clean database instance, migrations were failing with errors:

1. Duplicate column 'publishOn':
   Error: Duplicate column name 'publishOn'
   at PromisePool.query
   sql: 'ALTER TABLE anchorPodcastEpisodes ADD COLUMN publishOn DATETIME DEFAULT NULL AFTER created'

2. Missing table 'hosterPodcastMetrics':
   Error: Table 'openpodcast.hosterPodcastMetrics' doesn't exist
   sql: 'ALTER TABLE hosterPodcastMetrics MODIFY dimension ENUM(...)'

Root cause: schema.sql contained changes that were supposed to be applied
via migrations (migration 6 for publishOn, migration 17 for hoster enum values).
When migrations ran after schema.sql on a fresh DB, they tried to add/modify
things that already existed.

Fix: Remove migration changes from schema.sql so it reflects the base state
before migrations run. Migrations then apply changes incrementally:
- Removed 'publishOn' column (added by migration 6)
- Removed 'listeners' and 'subscribers' from hosterPodcastMetrics enum (added by migration 17)

This ensures schema.sql and migrations don't conflict on fresh installs.
@mre mre requested a review from woolfg October 1, 2025 13:57
@mre
Copy link
Member Author

mre commented Oct 6, 2025

Weird, it works on @woolfg's machine. Could be an issue on my side. We discussed it offline.

A simple make down up on main worked for him:

api-1  | MySQL tables don't exist in the specified db, creating them...
api-1  | tables created
api-1  | Running sql statements ...
api-1  | sql statements executed
api-1  | ⚡️[server]: Open Podcast is running at http://localhost:8080/ 

To be investigated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants